<?php defined('SYSPATH') or die('No direct script access.');
/**
 *
 * $Id$
 *
 * @package    DynamicImage
 * @author     Polaris Digital
 * @copyright  (c) 2008 Polaris Digital
 * @license    GNU Public Licence v3
 */
class DynamicImage_Controller extends Controller {

	public function index( $args = FALSE )
	{
		if( $this->input->get('file') )
		{
			$image_settings = array
				(
					'width'	  				=> $this->input->get('width') ? $this->input->get('width') : FALSE,
					'height'   				=> $this->input->get('height') ? $this->input->get('height') : FALSE,
					'maintain_ratio' 		=> $this->input->get('mr') ? $this->input->get('mr') : FALSE,
					'format'				=> $this->input->get('format') ? $this->input->get('format') : FALSE,
					'maintain_transparency'	=> $this->input->get('mt') ? $this->input->get('mt') : FALSE,
					'background'			=> $this->input->get('bk') ? DynamicImage::hexrgb( $this->input->get('bk'), FALSE ) : array( 255,255,255 ),
					'auto_crop'				=> $this->input->get('cr') ?  (float) $this->input->get('cr') : FALSE
				);
							
			$myimage = new DynamicImage( $this->input->get('file'), $image_settings );					
		}
		else
		{
			throw new Kohana_Exception('An image resource in GIF, JPG or PNG format is required');
		}
	}
	
	/**
	 * Overloading the controller to handle full file paths with internally encoded URL's
	 *
	 * @param string $method 
	 * @param string $args 
	 * @return void
	 * @author Sam Clark
	 */
	public function __call( $method, $args )
	{
		if( $image_settings = DynamicImage::validate_full_path( $this->uri->segment_array( 1 ) ) )
		{
			$myimage = new DynamicImage( $image_settings[ 'filename' ], $image_settings[ 'settings' ] );				
		}
		else
		{
			throw new Kohana_Exception('An image resource in GIF, JPG or PNG format is required');			
		}
		
	}
	
}